package com.hyl.controller;

import com.hyl.entity.SysUser;
import com.hyl.service.SysUserService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

/**
 * LoginController
 *
 * @author hyl
 * @date 2025-07-02
 */
@Controller
public class LoginController extends BaseController {

    @Autowired
    private SysUserService userService;

    @PostMapping("/login")  //请求：user/login ==>LoginController.login()
    public String login(String account, String password, Model model, HttpServletRequest request){
        SysUser user = userService.login(account, password);
        if (user != null){
            setCurrentUser(user);
            return "index";
        }
        return "login";
    }

    /** 保存或修改数据接口 */
    @PostMapping("/save")
    public String doSave(SysUser sysUser,
                         MultipartFile idPic, MultipartFile workPic){
        System.out.println("上传");
        return "index";
    }
}
